Skip to content

SISC-BE-151 게시판 반환값 변경#129

Merged
discipline24 merged 10 commits intomainfrom
SIsC1-151-BE-게시판-추가
Nov 20, 2025

Hidden character warning

The head ref may contain hidden characters: "SIsC1-151-BE-\uac8c\uc2dc\ud310-\ucd94\uac00"
Merged

SISC-BE-151 게시판 반환값 변경#129
discipline24 merged 10 commits intomainfrom
SIsC1-151-BE-게시판-추가

Conversation

@nayoung04
Copy link
Contributor

@nayoung04 nayoung04 commented Nov 20, 2025

Summary by CodeRabbit

릴리스 노트

  • 개선 사항
    • API 응답의 사용자 정보 직렬화 일관성 개선
    • 게시물, 댓글, 보드 관련 데이터 표현 최적화
    • 중첩된 데이터 구조의 안정성 강화

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Nov 20, 2025

개요

보드 관련 DTO들(BoardResponse, CommentResponse, PostResponse)과 사용자 DTO(UserInfoResponse)의 팩토리 메서드를 of()에서 from()으로 일관되게 이름 변경하고, 엔티티 참조를 DTO 참조로 대체하는 리팩토링입니다.

변경사항

응집도 / 파일 변경 요약
DTO 필드 타입 업데이트
backend/src/main/java/org/sejongisc/backend/board/dto/BoardResponse.java, CommentResponse.java, PostResponse.java
User 엔티티를 UserInfoResponse DTO로 대체. Board 엔티티를 BoardResponse DTO로 대체(PostResponse에만 해당). 각 DTO의 필드 타입 및 import 문 업데이트.
팩토리 메서드 이름 통일
backend/src/main/java/org/sejongisc/backend/board/dto/BoardResponse.java, CommentResponse.java
정적 팩토리 메서드 이름을 of(...)from(...)으로 통일. BoardResponse, CommentResponse의 모든 팩토리 메서드 시그니처 변경.
UserInfoResponse 팩토리 메서드 추가
backend/src/main/java/org/sejongisc/backend/user/dto/UserInfoResponse.java
from(CustomUserDetails), from(User) 두 개의 정적 팩토리 메서드 추가. null 안전 처리 포함.
서비스 계층 업데이트
backend/src/main/java/org/sejongisc/backend/board/service/PostServiceImpl.java
변경된 팩토리 메서드 호출 반영(CommentResponse, BoardResponse). PostResponse 생성 시 DTO 컨버터 사용(BoardResponse.from, UserInfoResponse.from). mapToPostResponse 메서드에서 엔티티 대신 DTO 변환 적용.
테스트 업데이트
backend/src/test/java/org/sejongisc/backend/board/service/PostServiceImplTest.java
테스트 픽스처 확장(email, name, role, boardName, createdBy). DTO 변환 결과 검증 강화. 새로운 필드 관계 반영.

예상 코드 리뷰 난이도

🎯 3 (중간) | ⏱️ ~20분

추가 주의 사항:

  • UserInfoResponse의 새 팩토리 메서드에서 null 안전 처리 검증 필요
  • PostServiceImpl에서 DTO 변환이 모든 경로에서 일관되게 적용되었는지 확인
  • PostResponse 필드 타입 변경(Board → BoardResponse)이 직렬화/역직렬화에 미치는 영향 검토
  • 테스트에서 mock 객체의 필수 필드 초기화가 충분한지 검증

관련 가능성 있는 PR

제안 검토자

  • discipline24

🐰 엔티티는 물러나고 DTO가 나서니,
팩토리 메서드 from()으로 통일되어,
타입 안전과 관심사 분리 완성!
보드와 댓글, 포스트 모두 깔끔하게
DTO의 세계로 여행을 떠나네~

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 13.33% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR 제목이 주요 변경 사항을 정확하게 설명합니다. 게시판 응답값 변경이라는 핵심 내용을 간결하게 전달합니다.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch SIsC1-151-BE-게시판-추가

Tip

📝 Customizable high-level summaries are now available in beta!

You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.

  • Provide your own instructions using the high_level_summary_instructions setting.
  • Format the summary however you like (bullet lists, tables, multi-section layouts, contributor stats, etc.).
  • Use high_level_summary_in_walkthrough to move the summary from the description to the walkthrough section.

Example instruction:

"Divide the high-level summary into five sections:

  1. 📝 Description — Summarize the main change in 50–60 words, explaining what was done.
  2. 📓 References — List relevant issues, discussions, documentation, or related PRs.
  3. 📦 Dependencies & Requirements — Mention any new/updated dependencies, environment variable changes, or configuration updates.
  4. 📊 Contributor Summary — Include a Markdown table showing contributions:
    | Contributor | Lines Added | Lines Removed | Files Changed |
  5. ✔️ Additional Notes — Add any extra reviewer context.
    Keep each section concise (under 200 words) and use bullet or numbered lists for clarity."

Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
backend/src/main/java/org/sejongisc/backend/user/dto/UserInfoResponse.java (1)

77-85: User를 직접 변환하는 것을 고려해보세요.

현재 from(User) 메서드는 CustomUserDetails 객체를 임시로 생성한 후 다시 from(CustomUserDetails)를 호출합니다. 이는 일관성을 유지하지만, 불필요한 객체 생성이 발생합니다.

더 효율적인 구현을 원하신다면 다음과 같이 직접 변환할 수 있습니다:

  public static UserInfoResponse from(User user) {
    if (user == null) {
      return null;
    }

-   CustomUserDetails userDetails = new CustomUserDetails(user);
-
-   return from(userDetails);
+   return new UserInfoResponse(
+       user.getUserId(),
+       user.getName(),
+       user.getEmail(),
+       user.getPhoneNumber(),
+       user.getPoint(),
+       user.getRole().name(),
+       List.of(new SimpleGrantedAuthority(user.getRole().name()))
+   );
  }

다만 현재 구현도 코드 중복을 피하고 일관성을 유지하므로, 성능이 문제가 되지 않는다면 유지해도 무방합니다.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 27f1c1a and f44fc12.

📒 Files selected for processing (6)
  • backend/src/main/java/org/sejongisc/backend/board/dto/BoardResponse.java (2 hunks)
  • backend/src/main/java/org/sejongisc/backend/board/dto/CommentResponse.java (2 hunks)
  • backend/src/main/java/org/sejongisc/backend/board/dto/PostResponse.java (2 hunks)
  • backend/src/main/java/org/sejongisc/backend/board/service/PostServiceImpl.java (4 hunks)
  • backend/src/main/java/org/sejongisc/backend/user/dto/UserInfoResponse.java (2 hunks)
  • backend/src/test/java/org/sejongisc/backend/board/service/PostServiceImplTest.java (8 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
backend/src/main/java/org/sejongisc/backend/user/dto/UserInfoResponse.java (2)
backend/src/main/java/org/sejongisc/backend/auth/dto/SignupResponse.java (1)
  • Getter (12-77)
backend/src/main/java/org/sejongisc/backend/common/auth/springsecurity/CustomUserDetails.java (1)
  • Getter (14-70)
🔇 Additional comments (7)
backend/src/main/java/org/sejongisc/backend/board/dto/BoardResponse.java (1)

25-25: 엔티티를 DTO로 올바르게 분리했습니다.

User 엔티티를 UserInfoResponse DTO로 변경하고 팩토리 메서드명을 of에서 from으로 변경한 것은 적절합니다. 이는 API 응답에서 엔티티를 직접 노출하지 않는 모범 사례를 따릅니다.

Also applies to: 29-36

backend/src/test/java/org/sejongisc/backend/board/service/PostServiceImplTest.java (2)

90-110: 테스트 픽스처가 DTO 변환을 잘 지원합니다.

DTO 변환 시 NPE를 방지하기 위해 mockUser에 필수 필드(email, name, role)를 추가하고, mockBoardmockParentBoardboardNamecreatedBy를 추가한 것은 적절합니다.


259-260: DTO 변환 검증이 추가되어 좋습니다.

DTO 변환 후 user.getName()board.getBoardName() 검증을 추가하여 변환이 올바르게 수행되는지 확인하고 있습니다.

backend/src/main/java/org/sejongisc/backend/board/dto/PostResponse.java (1)

24-25: 응답 DTO에서 엔티티 타입을 DTO 타입으로 변경했습니다.

BoardBoardResponse로, UserUserInfoResponse로 변경하여 API 응답에서 엔티티를 직접 노출하지 않도록 개선했습니다.

backend/src/main/java/org/sejongisc/backend/board/dto/CommentResponse.java (1)

23-23: 엔티티를 DTO로 일관되게 변환했습니다.

User 엔티티를 UserInfoResponse DTO로 변경하고 팩토리 메서드를 from으로 통일한 것은 다른 DTO들과 일관성을 유지합니다. 대댓글이 있는 경우와 없는 경우를 모두 처리하는 오버로드된 메서드도 적절합니다.

Also applies to: 30-39, 41-51

backend/src/main/java/org/sejongisc/backend/board/service/PostServiceImpl.java (2)

26-26: 서비스 계층에서 DTO 변환을 올바르게 구현했습니다.

BoardResponse.from(), UserInfoResponse.from(), CommentResponse.from() 등 DTO 팩토리 메서드를 일관되게 사용하여 엔티티를 DTO로 변환하고 있습니다. 이는 서비스 계층과 프레젠테이션 계층의 책임을 명확히 분리합니다.

Also applies to: 239-243, 255-256, 306-306, 313-314


233-244: N+1 쿼리 문제를 인지하고 있는지 확인해주세요.

현재 구현은 부모 댓글 각각에 대해 commentRepository.findByParentComment(parent)를 호출하여 N+1 쿼리 문제가 발생합니다. 댓글이 많은 게시물의 경우 성능 이슈가 될 수 있습니다.

다음과 같은 방법으로 개선을 고려해볼 수 있습니다:

  1. Batch Fetch Size 설정: JPA의 @BatchSize 어노테이션 사용
  2. Fetch Join 사용: 부모-자식 댓글을 한 번에 조회
  3. 별도 쿼리로 일괄 조회: 부모 댓글 ID 목록으로 자식 댓글을 한 번에 조회 후 메모리에서 매핑

현재 기능에 문제가 없다면 추후 성능 개선 작업으로 미뤄도 됩니다. 다만 댓글 수가 많아질 가능성을 고려하여 모니터링이 필요합니다.

@discipline24 discipline24 merged commit c5c0794 into main Nov 20, 2025
1 check passed
@discipline24 discipline24 deleted the SIsC1-151-BE-게시판-추가 branch November 20, 2025 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants